package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.MangerService;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.implementation.bind.annotation.Origin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class BaseManageController {

    @Autowired
    MangerService mangerService;

    @GetMapping("getCategory1")
    public Result getCategory1(){
        List<BaseCategory1> baseCategory1List =  mangerService.getCategory1();
        return Result.ok(baseCategory1List);
    }

    @GetMapping("getCategory2/{CategoryId}")
    public Result getCategory2(@PathVariable Long CategoryId){
        List<BaseCategory2> baseCategory2List = mangerService.CategoryId(CategoryId);
        return Result.ok(baseCategory2List);
    }

    @GetMapping("getCategory3/{CategoryId2}")
    public Result getCategory3(@PathVariable Long CategoryId2){
        List<BaseCategory3> BaseCategory3List = mangerService.getCategoryId3(CategoryId2);
        return Result.ok(BaseCategory3List);
    }

    @GetMapping("attrInfoList/{CategoryId}/{CategoryId2}/{CategoryId3}")
    public Result attrInfoLisL(@PathVariable("CategoryId") Long CategoryId,
                               @PathVariable("CategoryId2") Long CategoryId2,
                               @PathVariable("CategoryId3") Long CategoryId3){
        List<BaseAttrInfo> baseAttrInfoList = mangerService.
                attrInfoList(CategoryId,CategoryId2,CategoryId3);
        return Result.ok(baseAttrInfoList);
    }
    @PostMapping("saveAttrInfo")
    public Result saveAttrInfo(@RequestBody  BaseAttrInfo baseAttrInfo){
        this.mangerService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }
    @GetMapping("getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable Long attrId){
        BaseAttrInfo baseAttrInfo = this.mangerService.getBaseAttrInfo(attrId);
        //List<BaseAttrValue> BaseAttrValueList = mangerService.getAttrValueList(attrId);
        return Result.ok(baseAttrInfo.getAttrValueList());
    }
}
